<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<head>
<style type="text/css">
h1 span{visibility:visible;}
td span{visibility:visible;}
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
</head>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="frontHostname" value='<%=ServerValue.getFrontHostname() %>'/>
<!-- 广告代码验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.autotab-1.1b.js"></script>

<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		
		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#top4TagForm").submit();
			}
		});

		/*
		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#top4TagForm").submit();
			}
		});
		*/
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#top4TagForm").submit();
			}
		});
		
		$(":input[id*='adWord']").alphanumeric();
		$(":input[id*='adWord']").autotab_filter({ format: 'custom', pattern: '[^a-zA-Z0-9]' });
	});
	
	function validate_data(){
		var isCorrect = true;
		
		$("span:[id*=title]").hide();
		$("span:[id*=title]").text('');
		
		for( var i = 4; i >= 1; i-- ){
			if ( $("#title" + i + "Url").val() == "" ){
				appendWord($("#title" + i + "Tip"),"请输入点击连结");
				$("#title" + i + "Tip").show();
				$("#title" + i + "Url").focus();
				isCorrect = false;
			}else if(!isURL($("#title" + i + "Url").val())){
				appendWord($("#title" + i + "Tip"),"点击连结格式错误");
				$("#title" + i + "Tip").show();
				$("#title" + i + "Url").focus();
				isCorrect = false;
			}
			
			if ( $("#title" + i + "Name").val() == "" ){
				appendWord($("#title" + i + "Tip"),"请输入文字标题");
				$("#title" + i + "Tip").show();
				$("#title" + i + "Name").focus();
				isCorrect = false;
			}else if(!vaildateLength(8,$("#title" + i + "Name").val())){
				appendWord($("#title" + i + "Tip"),"文字标题长度超出限制");
				$("#title" + i + "Tip").show();
				$("#title" + i + "Name").focus();
				isCorrect = false;
			}
		}
		
		if($('#startDate').val()==''){
			$('#startDateTip').text('请输入起始日期');
			$('#startDateTip').show();
			$('#startDate').focus();
			isCorrect = false;
		}else{
			$('#startDateTip').hide();
			$('#startDateTip').text('');
		}
		
		if($('#startTime').val()==''){
			$('#startTimeTip').text('请输入起始时间');
			$('#startTimeTip').show();
			$('#startTime').focus();
			isCorrect = false;
		}else{
			$('#startTimeTip').hide();
			$('#startTimeTip').text('');
		}
		
		if($('#endDate').val()==''){
			$('#endDateTip').text('请输入结束日期');
			$('#endDateTip').show();
			$('#endDate').focus();
			isCorrect = false;
		}else{
			$('#endDateTip').hide();
			$('#endDateTip').text('');
		}
		
		if($('#endTime').val()==''){
			$('#endTimeTip').text('请输入结束时间');
			$('#endTimeTip').show();
			$('#endTime').focus();
			isCorrect = false;
		}else{
			$('#endTimeTip').hide();
			$('#endTimeTip').text('');
		}
		
		if($('#startDate').val()>$('#endDate').val()){
			$('#endDateTip').text('结束日期不能小于起始日期');
			$('#endDateTip').show();
			$('#startDate').focus();
			isCorrect = false;
		}else if($('#startDate').val()==$('#endDate').val()){
			if($('#startTime').val()>=$('#endTime').val()){
				$('#endTimeTip').text('结束时间需大于起始时间');
				$('#endTimeTip').show();
				$('#startDate').focus();
				isCorrect = false;
			}else{
				$('#endTimeTip').hide();
				$('#endTimeTip').text('');
			}
		}else{
			$('#endDateTip').hide();
			$('#endDateTip').text('');
		}
		
		if ( $("#advName").val() == "" ){
			$("#advNameTip").text("请输入广告名称");
			$("#advNameTip").show();
			$("#advName").focus();
			isCorrect = false;
		}else{
			$('#advNameTip').hide();
			$('#advNameTip').text('');
		}
		
		return isCorrect;
	}

	function appendWord(origin, apptext){
		if(origin.text().length==0){
			origin.text(apptext);
		}else{
			origin.text(origin.text()+', '+apptext);
		}
		
	}
</script>
<h1>
	广告管理 - 四头标（页首文字广告连结）
	<br/>
	<div class="f-link">
		<a href="${midContextPath}/generate/idxV5/searchIdx.do">回广告查询页</a>
	</div>
</h1>
<s:if test="hasErrors()">
<p><s:actionerror cssClass="msg rn" /></p>
</s:if>
<s:if test="hasActionMessages()">
<p><s:actionmessage cssClass="msg rn" /></p>
</s:if>
<s:if test="hasFieldErrors()">
<p><s:fielderror cssClass="msg rn" /></p>
</s:if>
<s:form action="top4Tag/saveTop4Tag.do" method="post" name="top4TagForm" id="top4TagForm">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>首页 - 四头标（页首文字广告连结）<input type="hidden" name="advType" id="advType" value="${advType}"/></td>
			</tr>
			<tr>
				<th>广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/><br/><span id="advNameTip" class="msg rn" style="display:none;"></span></td>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td>
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/>
				<select id="startTime" name="startTime">			
						<c-rt:forEach begin="0" end="23" var="t1">
							<c-rt:if test="${t1<10}">
							<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<c-rt:if test="${t1>=10}">
							<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
							</c-rt:if>
							<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
						</c-rt:forEach>
				</select>  
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
				<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
				</select>
				<span id="startDateTip" class="msg rn" style="display:none;"></span><span id="startTimeTip" class="msg rn" style="display:none;"></span><span id="endDateTip" class="msg rn" style="display:none;"></span><span id="endTimeTip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<td colspan="4"><img src="/eventImg/TOP4_TAG.jpg"></th>
			</tr>
			<tr>
				<th colspan="4">title设定</th>
			</tr>
			<tr>
				<th>标题1</th>
				<td>
					<b>*文字标题一</b><input type="text" name="title1Name" id="title1Name" value="${title1Name}" maxlength="16" size="30"/><span class="txt-rd">字数限制:8个中文字或16个英文字母或数字</span>
					&nbsp;&nbsp;字体是否强化效果:
					<input type="radio" name="isHighlight1" value="Y" id="isHighlight1_y" <c-rt:if test="${isHighlight1 eq 'Y'}">checked="checked"</c-rt:if>/>是 
					<input type="radio" name="isHighlight1" value="N" id="isHighlight1_n" <c-rt:if test="${isHighlight1 != 'Y'}">checked="checked"</c-rt:if>/>否  *四头标以红字加强显示<br/>
					<b>*点击连结</b><input type="text" name="title1Url" id="title1Url" size="30" value="${title1Url}"/><span class="txt-rd">ex:http://www.yaodian100.com</span><br/>
					<b>广告代码</b><input type="text" name="title1adWord" id="title1adWord" value="${title1adWord}" maxlength="25" size="20"/><span class="txt-rd">非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<span id="title1Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>标题2</th>
				<td>
					<b>*文字标题二</b><input type="text" name="title2Name" id="title2Name" value="${title2Name}" maxlength="16" size="30"/><span class="txt-rd">字数限制:8个中文字或16个英文字母或数字</span>
					&nbsp;&nbsp;字体是否强化效果:
					<input type="radio" name="isHighlight2" value="Y" id="isHighlight2_y" <c-rt:if test="${isHighlight2 eq 'Y'}">checked="checked"</c-rt:if>/>是 
					<input type="radio" name="isHighlight2" value="N" id="isHighlight2_n" <c-rt:if test="${isHighlight2 != 'Y'}">checked="checked"</c-rt:if>/>否  *四头标以红字加强显示<br/>
					<b>*点击连结</b><input type="text" name="title2Url" id="title2Url" size="30" value="${title2Url}"/><span class="txt-rd">ex:http://www.yaodian100.com</span><br/>
					<b>广告代码</b><input type="text" name="title2adWord" id="title2adWord" value="${title2adWord}" maxlength="25" size="20"/><span class="txt-rd">非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<span id="title2Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
			<tr>
				<th>标题3</th>
				<td>
					<b>*文字标题三</b><input type="text" name="title3Name" id="title3Name" value="${title3Name}" maxlength="16" size="30"/><span class="txt-rd">字数限制:8个中文字或16个英文字母或数字</span>
					&nbsp;&nbsp;字体是否强化效果:
					<input type="radio" name="isHighlight3" value="Y" id="isHighlight3_y" <c-rt:if test="${isHighlight3 eq 'Y'}">checked="checked"</c-rt:if>/>是 
					<input type="radio" name="isHighlight3" value="N" id="isHighlight3_n" <c-rt:if test="${isHighlight3 != 'Y'}">checked="checked"</c-rt:if>/>否  *四头标以红字加强显示<br/>
					<b>*点击连结</b><input type="text" name="title3Url" id="title3Url" size="30" value="${title3Url}"/><span class="txt-rd">ex:http://www.yaodian100.com</span><br/>
					<b>广告代码</b><input type="text" name="title3adWord" id="title3adWord" value="${title3adWord}" maxlength="25" size="20"/><span class="txt-rd">非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<span id="title3Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>	
			<tr>
				<th>标题4</th>
				<td>
					<b>*文字标题四</b><input type="text" name="title4Name" id="title4Name" value="${title4Name}" maxlength="16" size="30"/><span class="txt-rd">字数限制:8个中文字或16个英文字母或数字</span>
					&nbsp;&nbsp;字体是否强化效果:
					<input type="radio" name="isHighlight4" value="Y" id="isHighlight4_y" <c-rt:if test="${isHighlight4 eq 'Y'}">checked="checked"</c-rt:if>/>是 
					<input type="radio" name="isHighlight4" value="N" id="isHighlight4_n" <c-rt:if test="${isHighlight4 != 'Y'}">checked="checked"</c-rt:if>/>否  *四头标以红字加强显示<br/>
					<b>*点击连结</b><input type="text" name="title4Url" id="title4Url" size="30" value="${title4Url}"/><span class="txt-rd">ex:http://www.yaodian100.com</span><br/>
					<b>广告代码</b><input type="text" name="title4adWord" id="title4adWord" value="${title4adWord}" maxlength="25" size="20"/><span class="txt-rd">非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<span id="title4Tip" class="msg rn" style="display:none;"></span>
				</td>
			</tr>
		<c-rt:if test="${not empty advId}">
			<tr>
				<th>修改记录</th>
				<td>
					<p>建立：<fmt:formatDate value="${createDate}" pattern="yyyy-MM-dd HH:mm"/> / ${createUser}</p>
					<p>修改：<fmt:formatDate value="${modifyDate}" pattern="yyyy-MM-dd HH:mm"/> / ${modifyUser}</p>
				</td>
			</tr>
		</c-rt:if>
			<tr>
				<td colspan="2">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
<!-- 					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/> -->
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/generate/idxV5/searchIdx.do">回广告查询页</a>
</div>